package com.guet.niit.Login.controller.user;

import com.guet.niit.User.pojo.ChargingRecord;
import com.guet.niit.User.pojo.UserCar;
import com.guet.niit.util.UserBacktrack;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.image.ImageView;
import javafx.scene.input.MouseEvent;
import javafx.scene.text.Text;

import java.net.URL;
import java.util.*;

public class ChargingRecordFxController implements Initializable {

    public static ChargingRecordFxController chargingRecordFxController;

    @FXML
    private ImageView backtrack;

    @FXML
    private Text chargingStartTime0;

    @FXML
    private Text chargingRunTime0;

    @FXML
    private Text chargingCost0;

    @FXML
    private Text chargingStation0;

    @FXML
    private Text userCar0;

    @FXML
    private Text status0;

    @FXML
    private Text chargingStartTime1;

    @FXML
    private Text chargingRunTime1;

    @FXML
    private Text chargingCost1;

    @FXML
    private Text chargingStation1;

    @FXML
    private Text userCar1;

    @FXML
    private Text status1;

    @FXML
    private Text chargingStartTime2;

    @FXML
    private Text chargingRunTime2;

    @FXML
    private Text chargingCost2;

    @FXML
    private Text chargingStation2;

    @FXML
    private Text userCar2;

    @FXML
    private Text status2;

    @FXML
    private Text chargingStartTime3;

    @FXML
    private Text chargingRunTime3;

    @FXML
    private Text chargingCost3;

    @FXML
    private Text chargingStation3;

    @FXML
    private Text userCar3;

    @FXML
    private Text status3;

    @FXML
    private Text chargingStartTime4;

    @FXML
    private Text chargingRunTime4;

    @FXML
    private Text chargingCost4;

    @FXML
    private Text chargingStation4;

    @FXML
    private Text userCar4;

    @FXML
    private Text status4;

    @Override
    public void initialize(URL location, ResourceBundle resources) {
        chargingRecordFxController = this;
    }

    /**
     * 返回用户菜单
     * @param mouseEvent
     */
    public void backtrack(MouseEvent mouseEvent) {
        UserBacktrack.backtrack(ChargingRecordFxController.class);
    }

    /**
     * 读取个人充电记录
     */
    public void readChargingRecord(ArrayList<ChargingRecord> chargingRecords,ArrayList<UserCar> userCars){
        //根据记录的条数动态展示充电记录
        chargingStartTime0.setText(chargingRecords.get(0).getStart_time().toString());
        chargingRunTime0.setText(chargingRecords.get(0).getRun_time()+"分钟");
        chargingCost0.setText(chargingRecords.get(0).getCost()+"元");
        userCar0.setText(userCars.get(0).getCarName());
        String status = "";
        if (chargingRecords.get(0).getStatus()==0){
            status = "正在充电";
        }else {
            status = "已结束";
        }
        status0.setText(status);

        if (chargingRecords.size()==2){
            chargingStartTime1.setText(chargingRecords.get(1).getStart_time().toString());
            chargingRunTime1.setText(chargingRecords.get(1).getRun_time()+"分钟");
            chargingCost1.setText(chargingRecords.get(1).getCost()+"元");
            userCar1.setText(userCars.get(1).getCarName());
            if (chargingRecords.get(1).getStatus()==0){
                status = "正在充电";
            }else {
                status = "已结束";
            }
            status1.setText(status);
        }
        if (chargingRecords.size()==3){
            chargingStartTime2.setText(chargingRecords.get(2).getStart_time().toString());
            chargingRunTime2.setText(chargingRecords.get(2).getRun_time()+"分钟");
            chargingCost2.setText(chargingRecords.get(2).getCost()+"元");
            userCar2.setText(userCars.get(2).getCarName());
            if (chargingRecords.get(2).getStatus()==0){
                status = "正在充电";
            }else {
                status = "已结束";
            }
            status2.setText(status);
        }
        if (chargingRecords.size()==4){
            chargingStartTime3.setText(chargingRecords.get(3).getStart_time().toString());
            chargingRunTime3.setText(chargingRecords.get(3).getRun_time()+"分钟");
            chargingCost3.setText(chargingRecords.get(3).getCost()+"元");
            userCar3.setText(userCars.get(3).getCarName());
            if (chargingRecords.get(3).getStatus()==0){
                status = "正在充电";
            }else {
                status = "已结束";
            }
            status3.setText(status);
        }
        if (chargingRecords.size()==5){
            chargingStartTime4.setText(chargingRecords.get(4).getStart_time().toString());
            chargingRunTime4.setText(chargingRecords.get(4).getRun_time()+"分钟");
            chargingCost4.setText(chargingRecords.get(4).getCost()+"元");
            userCar4.setText(userCars.get(4).getCarName());
            if (chargingRecords.get(4).getStatus()==0){
                status = "正在充电";
            }else {
                status = "已结束";
            }
            status4.setText(status);
        }
    }
}
